//
//  MYTipUtils.m
//  MiaoYin
//
//  Created by 多多 on 2019/12/28.
//  Copyright © 2019 thy. All rights reserved.
//

#import "MYTipUtils.h"
#import "UIImage+gif.h"

@implementation MYTipUtils

#pragma mark - 提示框
/**
 自身的弹窗，简单的文字弹窗
 
 @param aletString 弹窗内容
 */
+ (void)showAlertString:(NSString *)aletString
{
    QMUITips *tips = [QMUITips showWithText:aletString];
    tips.backgroundView.backgroundColor = [UIColor colorWithUInt:0x323232 alpha:0.85];
}
/**
自身的弹窗，简单的loading弹窗

@param aletString 弹窗内容
@param view  添加的view
*/
+ (void)showLoadingAlertString:(nullable NSString *)aletString inView:(UIView *)view
{
//    QMUITips *tips = [QMUITips showLoading:aletString inView:view];
//    tips.backgroundView.backgroundColor = [UIColor colorWithUInt:0x323232 alpha:0.85];
    
    [SVProgressHUD setImageViewSize:CGSizeMake(60, 60)];
    [SVProgressHUD setMinimumDismissTimeInterval:MAXFLOAT];
    [SVProgressHUD setBackgroundColor:[UIColor blackColor]];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
}
/**
自身的弹窗，简单的info弹窗

@param aletString 弹窗内容 ic_QMUI_tips_done
*/
+ (void)showInfoAlertString:(NSString *)aletString
{
    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
    img.image = [UIImage imageNamed:@"ic_showInfo_white"];

    QMUITips *tips = [QMUITips showLoading:aletString inView:[[[UIApplication sharedApplication] delegate] window] hideAfterDelay:2];
    tips.backgroundView.backgroundColor = [UIColor colorWithUInt:0x323232 alpha:0.85];
    QMUIToastContentView *bgView = tips.contentView;
    bgView.customView = img;
    
//    QMUITips *tips = [QMUITips showInfo:aletString];
//    tips.backgroundView.backgroundColor = [UIColor colorWithUInt:0x000000 alpha:0.5];
}
/**
 自身的弹窗，简单的成功文字弹窗
 
 @param aletString 弹窗内容
 */
+ (void)showSuccessAlertString:(NSString *)aletString
{
    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
    img.image = [UIImage imageNamed:@"icon_toast_success"];

    QMUITips *tips = [QMUITips showLoading:aletString inView:[[[UIApplication sharedApplication] delegate] window] hideAfterDelay:2];
    tips.backgroundView.backgroundColor = [UIColor colorWithUInt:0x323232 alpha:0.85];
    QMUIToastContentView *bgView = tips.contentView;
    bgView.customView = img;
    
//    QMUITips *tips = [QMUITips showSucceed:aletString];
//    tips.backgroundView.backgroundColor = [UIColor colorWithUInt:0x000000 alpha:0.5];
}
/**
 自身的弹窗，简单的错误文字弹窗
 
 @param aletString 弹窗内容
 */
+ (void)showErrorAlertString:(NSString *)aletString
{
    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
//    UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_error_white"]];
    img.image = [UIImage imageNamed:@"ic_error_white"];

    QMUITips *tips = [QMUITips showLoading:aletString inView:[[[UIApplication sharedApplication] delegate] window] hideAfterDelay:2];
    tips.backgroundView.backgroundColor = [UIColor colorWithUInt:0x323232 alpha:0.85];
    QMUIToastContentView *bgView = tips.contentView;
    bgView.customView = img;
//    QMUITips *tips = [QMUITips showError:aletString];
//    tips.backgroundView.backgroundColor = [UIColor colorWithUInt:0x000000 alpha:0.5];
}
/**
 自身的弹窗，简单的文字弹窗
 @param aletString 弹窗内容
 @param duration 时长
 @param completion 完成回调
 */
+ (void)showSuccessAlertString:(NSString *)aletString
                      inView:(nonnull UIView *)inView
                    duration:(NSTimeInterval)duration
                  completion:(void(^)(void))completion
{
    
    [QMUITips showSucceed:aletString inView:inView hideAfterDelay:duration];
    dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, (duration) * NSEC_PER_SEC);
    dispatch_after(delay, dispatch_get_main_queue(), ^{
        // delay task
        if (completion) {
            completion();
        }
    });
}
/// 隐藏弹框
/// @param view 隐藏View在其上的弹框
+ (void)hideAllTipsInView:(UIView *)view
{
    [QMUITips hideAllToastInView:view animated:NO];
    [SVProgressHUD dismiss];
}
/// 隐藏所有弹框
+ (void)hideAllTips
{
    [QMUITips hideAllToastInView:nil animated:NO];
    [SVProgressHUD dismiss];
}

@end
